#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    // part 1
    char c = 'a';
    printf("c = %c, c: 0x%p;\n", c, &c);
    // part 2
    char *s1 = "hello world";
    printf("s1 = %s, s1: 0x%p, s1[0] = %c, sizeof(s1) = %d, strlen(s1) = %d;\n", s1, s1, s1[0], sizeof(s1), strlen(s1));
    char s2[10] = "thank you";
    printf("s2 = %s, s2: 0x%p, s2[0] = %c, sizeof(s2) = %d, strlen(s2) = %d;\n", s2, s2, s2[0], sizeof(s2), strlen(s2));
    s1 = "world hello";
    printf("s1' = %s;\n", s1);
    s1 = s2;
    printf("s1'' = %s;\n", s1);
    // error: s2 = "you thank";
    // error :s2 = s1;
    // part 3
    char *s3[] = {"apple", "orange", "banana"};
    printf("s3 = %s, s3: 0x%p;\n", s3, s3);
    printf("s3[0] = %s, s3[0]: 0x%p, s3[0][0] = %c, s3[0][0]: 0x%p, sizeof(s3[0]) = %d, strlen(s3[0]) = %d;\n", s3[0], s3[0], s3[0][0], &s3[0][0], sizeof(s3[0]), strlen(s3[0]));
    printf("s3[1] = %s, s3[1]: 0x%p, s3[1][0] = %c, s3[1][0]: 0x%p, sizeof(s3[1]) = %d, strlen(s3[1]) = %ld;\n", s3[1], s3[1], s3[1][0], &s3[1][0], sizeof(s3[1]), strlen(s3[1]));
    printf("s3[2] = %s, s3[2]: 0x%p, s3[2][0] = %c, s3[2][0]: 0x%p, sizeof(s3[2]) = %d, strlen(s3[2]) = %ld;\n", s3[2], s3[2], s3[2][0], &s3[2][0], sizeof(s3[2]), strlen(s3[2]));
    printf("sizeof(s3) = %d, sizeof(*s3) = %d, sizeof(**s3) = %d, strlen(*s3) = %d\n", sizeof(s3), sizeof(*s3), sizeof(**s3), strlen(*s3));
    printf("&s3[0]: 0x%p, &s3[1]: 0x%p, &s3[2]: 0x%p\n", &s3[0], &s3[1], &s3[2]);
    printf("*s3 = %s, *(s3 + 1) = %s, *(s3 + 2) = %s\n", *s3, *(s3 + 1), *(s3 + 2));
    char **s4 = s3;
    printf("s4 = %s, s4: 0x%p\n", s4, s4);
    printf("*s4 = %s, *s4: 0x%p\n", *s4, *s4);
    printf("**s4: 0x%p\n", **s4);
    printf("sizeof(s4) = %ul, sizeof(*s4) = %ul, sizeof(**s4) = %ul, strlen(*s4) = %ld\n", sizeof(s4), sizeof(*s4), sizeof(**s4), strlen(*s4));
    printf("&s4[0]: 0x%p, &s4[1]: 0x%p, &s4[2]: 0x%p\n", &s4[0], &s4[1], &s4[2]);
    printf("*s4 = %s, *(s4 + 1) = %s, *(s4 + 2) = %s\n", *s4, *(s4 + 1), *(s4 + 2));
    // part 4
    char **s5 = (char **)malloc(sizeof(char **));
    *s5 = "hello world";
    printf("s5: 0x%p, *s5: 0x%p, *s5 = %s\n", s5, *s5, *s5);
    *s5 = "thank you";
    printf("s5': 0x%p, *s5': 0x%p, *s5' = %s\n", s5, *s5, *s5);
    // part 5
    char *s6;
    char **s7 = &s6;
    *s7 = "hello world";
    printf("s6 = %s, s6: 0x%p\n", s6, s6);
    s6 = "thank you";
    printf("s6 = %s, s6: 0x%p\n", s6, s6);
    // while(getchar() != '\n') {}
    return 0;
} 